package com.igo.job;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.igo.domain.datacollection.devicedata.DeviceDataCalcd;
import com.igo.service.devicedata.DeviceDataCalcdService;
import com.igo.util.DeivceDataCalculateGantryCraneCa;
import com.igo.util.DeviceDataCalculateFlatCar;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;

@Slf4j
//@Component
public class DeviceDataCalculateJob {

    @Resource
    private DeivceDataCalculateGantryCraneCa deivceDataCalculateGantryCraneCa;

    @Resource
    private DeviceDataCalculateFlatCar deviceDataCalculateFlatCar;

    @Resource
    private DeviceDataCalcdService deviceDataCalcdService;

    @Scheduled(cron = "0 0/5 * * * ?")
    public String execute() throws Exception {
        System.out.println("执行 数采设备任务明细数据");
        Date date = new Date();
//一天的开始，结果：2017-03-01 00:00:00
        Date beginOfDay = DateUtil.beginOfDay(date);
//一天的结束，结果：2017-03-01 23:59:59
        Date endOfDay = DateUtil.endOfDay(date);
        //删除今日生成的数据
        deviceDataCalcdService.remove(new LambdaQueryWrapper<DeviceDataCalcd>()
                .ge(DeviceDataCalcd::getCreateTime,beginOfDay).le(DeviceDataCalcd::getCreateTime, endOfDay));
        deivceDataCalculateGantryCraneCa.calculateGantryCraneCaData(beginOfDay, endOfDay);
        deviceDataCalculateFlatCar.calculateFlatCarData(beginOfDay, endOfDay);
        return "success";
    }
}
